<template>
  <div class="container" v-bind:style="{height: windowHeight + 'px' }">
    <div class="choose_details" v-if="showfeat">
      <div class="list flex">
        <span class="words">{{year}}年度规划业绩</span>
        <input class="tool flex-item" type="digit" :value="yearfeat" @blur="setplan" placeholder="请填写年业绩" disabled="true" />
      </div>
    </div>
    <div class="submit" @tap="set" v-if="showfeat">修改</div>
    <div class="choose_details" v-if="!showfeat">
      <div class="list flex">
        <span class="words">{{year}}年度规划业绩</span>
        <input class="tool flex-item" type="digit" :value="yearplan" @blur="setplan" placeholder="请填写年业绩" />
      </div>
    </div>
    <div class="submit" @tap="postplan" v-if="!showfeat">确认</div>
  </div>
</template>

<script>
import wx from 'wx'
import moment from 'moment'
import api from '@/utils/api'
import Toast from '@/utils/toast'
export default {
  data () {
    return {
      windowHeight: 0,
      year: moment().year(),
      month: moment().month() + 1,
      choosevalue: '',
      featfocus: false,
      yearfeat: '',
      showfeat: false
    }
  },
  components: {
  },
  onLoad () {
    let that = this
    // 调用应用实例的方法获取全局数据
    // this.getUserInfo()
    wx.getSystemInfo({
      success (res) {
        that.windowHeight = res.windowHeight
      }
    })
    this.getinfo()
  },
  onShow () {
  },
  computed: {
  },
  methods: {
    async getinfo () {
      let userid = wx.getStorageSync('userInfo').user_id;
      const res = await api.getworkeryearplan({ user_id: userid, year: this.year });
      console.log(res)
      if (res.code === '100') {
        this.showfeat = true
        this.yearfeat = res.data[0].feat
      }
    },
    set () {
      this.showfeat = false
    },
    setplan (e) {
      this.yearplan = e.mp.detail.value
    },
    async postplan () {
      const that = this
      if (!that.yearplan) {
        Toast('请填写年度规划业绩', 'noicon');
        return;
      }
      let userid = wx.getStorageSync('userInfo').user_id;
      const res = await api.postguestplanyear({
        user_id: userid,
        year: that.year,
        month: '',
        text: that.yearplan
      })
      if (res.code === '100') {
        that.yearplan = ''
        Toast('提交成功', 'noicon');
        this.getinfo();
        this.showfeat = true
      } else {
        Toast('提交失败', 'noicon')
        that.yearplan = ''
      }
    }
  }
}
</script>

<style scoped>
.container {
  background: #fff !important;
}
.title {
  width: 100%;
  height: 80rpx;
  line-height: 80rpx;
  background: #fff;
  color: #333;
  padding: 0 20rpx;
  font-size: 28rpx;
}
.choose_details {
  width: 100%;
  background: #fff;
  padding: 28rpx;
}
.choose_details .list {
  width: 100%;
  height: 80rpx;
  line-height: 80rpx;
  border-bottom: 2rpx solid rgba(153, 153, 153, 0.1);
}
.choose_details .list .words {
  font-size: 28rpx;
  font-weight: 400;
  color: rgba(51, 51, 51, 1);
  opacity: 1;
  margin-right: 34rpx;
}
.choose_details .list .tool {
  font-size: 28rpx;
  font-weight: 400;
  color: rgba(153, 153, 153, 1);
  opacity: 1;
}
.textarea {
  padding-top: 18rpx;
  box-sizing: border-box;
  height: 128rpx;
  font-size: 28rpx;
}
.buttons {
  width: 432rpx;
  margin: 0 auto;
  margin-top: 40rpx;
}
.buttons .butinfo {
  width: 160rpx;
  height: 56rpx;
  background: linear-gradient(
    180deg,
    rgba(255, 68, 68, 0.6) 0%,
    rgba(255, 68, 68, 1) 100%
  );
  box-shadow: 0rpx 6rpx 12rpx rgba(255, 68, 68, 0.15);
  opacity: 1;
  border-radius: 24rpx;
  font-size: 28rpx;
  font-weight: 400;
  line-height: 56rpx;
  text-align: center;
  color: rgba(255, 255, 255, 1);
  margin-right: 112rpx;
}
.buttons .butinfo:last-child {
  margin-right: 0;
}
.goods_list {
  width: 100%;
  margin-top: 16rpx;
  background: #fff;
  padding: 32rpx;
  max-height: 600rpx;
}
.list_detail {
  width: 100%;
  font-size: 32rpx;
  font-weight: 400;
  line-height: 42rpx;
  color: rgba(51, 51, 51, 1);
  opacity: 1;
  margin-bottom: 34rpx;
}
.list_detail:last-child {
  margin: 0;
}
.choose_customer {
  /* 312*431 */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 111;
}
.choose_customer .customer_detail {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  width: 624rpx;
  height: 862rpx;
  background: rgba(255, 255, 255, 1);
  border-radius: 24rpx;
}
.choose_header {
  width: 100%;
  height: 86rpx;
  line-height: 86rpx;
  text-align: center;
  font-size: 32rpx;
  color: rgba(255, 68, 68, 1);
  border-bottom: 1rpx solid rgba(153, 153, 153, 0.1);
}
.right_arrow {
  position: absolute;
  top: 50%;
  right: 28rpx;
  width: 12rpx;
  height: 28rpx;
  background: url(http://mytimg.178mr.com/grey_arrow.png) no-repeat;
  background-size: 100%;
  transform: translateY(-50%);
}
.customer_ul {
  width: 100%;
  padding-left: 20rpx;
}
.customer_ul .customer_li {
  width: 100%;
  font-size: 32rpx;
  font-weight: 400;
  color: rgba(102, 102, 102, 1);
  border-bottom: 1rpx solid rgba(153, 153, 153, 0.1);
  position: relative;
}
.customer_pic {
  display: inline-block;
  width: 60rpx;
  height: 60rpx;
  position: relative;
  top: 10rpx;
  margin-right: 20rpx;
}
.customer_pic img {
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
}
.customer_name {
  display: inline-block;
  height: 60rpx;
  position: relative;
  top: -5rpx;
}
.submit {
  width: 321rpx;
  height: 80rpx;
  border-radius: 36rpx;
  background: linear-gradient(
    360deg,
    rgba(255, 68, 68, 1) 0%,
    rgba(255, 68, 68, 0.82) 38%,
    rgba(255, 68, 68, 0.51) 100%
  );
  line-height: 80rpx;
  text-align: center;
  font-size: 32rpx;
  color: #fff;
  margin: 0 auto;
  margin-top: 100rpx;
}
</style>
